package com.hsjk.szwj.module.train.service.impl;

import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveCreateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLivePageSearchRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveSearchPageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseLiveUpdateReqVO;
import com.hsjk.szwj.module.train.convert.CourseLiveConvert;
import com.hsjk.szwj.module.train.dal.dataobject.course.CourseLiveDO;
import com.hsjk.szwj.module.train.dal.mysql.course.ICourseLiveMapper;
import com.hsjk.szwj.module.train.service.ICourseLiveService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/10/28 16:05
 **/
@Service
public class CourseLiveServiceImpl implements ICourseLiveService {
    @Resource
    private ICourseLiveMapper courseLiveMapper;

    @Override
    public PageResult<AdminCourseLivePageRespVO> getCourseLivePage(AdminCourseLivePageReqVO reqVO) {
        PageResult<CourseLiveDO> courseLiveDOPageResult = courseLiveMapper.selectPage(reqVO);
        return CourseLiveConvert.INSTANCE.convertAdminCourseLivePageRespVO(courseLiveDOPageResult);
    }

    @Override
    public PageResult<AdminCourseLivePageSearchRespVO> getCourseLiveSearchPage(AdminCourseLiveSearchPageReqVO reqVO) {
        PageResult<CourseLiveDO> courseLiveDOPageResult = courseLiveMapper.selectPage(reqVO);
        return CourseLiveConvert.INSTANCE.convertAdminCourseLivePageSearchRespVO(courseLiveDOPageResult);
    }

    @Override
    public AdminCourseLiveDetailRespVO getCourseLiveDetail(Long id) {
        CourseLiveDO courseLiveDO = courseLiveMapper.selectById(id);
        return CourseLiveConvert.INSTANCE.convertAdminCourseLiveDetailRespVO(courseLiveDO);
    }

    @Override
    public Boolean createCourseLive(AdminCourseLiveCreateReqVO reqVO) {
        CourseLiveDO courseLiveDO = CourseLiveConvert.INSTANCE.convertCourseLiveDO(reqVO);
        int insert = courseLiveMapper.insert(courseLiveDO);
        return insert > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public Boolean updateCourseLive(AdminCourseLiveUpdateReqVO reqVO) {
        CourseLiveDO courseLiveDO = CourseLiveConvert.INSTANCE.convertCourseLiveDO(reqVO);
        int update = courseLiveMapper.updateById(courseLiveDO);
        return update > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public Boolean deleteCourseLive(Long id) {
        int result = courseLiveMapper.deleteById(id);
        return result > 0 ? Boolean.TRUE : Boolean.FALSE;
    }
}
